package cn.edu.cdp.gui.combo_box;

import cn.edu.cdp.dao.CollegeDao;
import cn.edu.cdp.domain.College;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.util.List;

@Component
public class ComboBoxCollege extends JComboBox<String> {
    @Autowired
    public ComboBoxCollege(CollegeDao collegeDao) {
        super();
        refreshData(collegeDao);
//        this.addItem("");
//        List<College> collegeList = collegeDao.allCollege();
//        for (College college : collegeList) {
//            this.addItem(college.getName());
//        }
    }

    public void refreshData(CollegeDao collegeDao) {
        this.removeAllItems();

        this.addItem("");
        List<College> collegeList = collegeDao.allCollege();
        for (College college : collegeList) {
            this.addItem(college.getName());
        }
    }
}
